<?

	require_once('../includes/includes.php');
	
	if ($_GET['ajax']=='imgupload') {
		if(file_exists('../includes/imageupload.ctcom.php')){
			require_once('../includes/imageupload.ctcom.php');
			$imageupload = new imageupload('imgbrowser'.sget('imgkeysed'));
			if(!$imageupload->check())
				$error = $imageupload->errString;
			else {
				$url = $imageupload->upload('../storage/data');
				if($imageupload->width > 500 || $imageupload->height > 500);
				if(in_array(spost('type'),array('logo')))
					$imageupload->resize($url,200,200);
				if(sget('imgkeysed') == 'icons') {
					if($imageupload->width > 30)
						$imageupload->resize($url,24,24);
				}
				 
				$dburl = str_replace('../','',$url);
			}
			$str = "{ error: '$error', dburl: '$dburl' , vurl : '$url' }";
			echo $str ;
			exit();
		}else {
			//FB::warn('==========');
			require_once('includes/imageupload.ctcom.php');
			$imageupload = new imageupload('imgbrowser'.sget('imgkeysed'));
			if(!$imageupload->check())
				$error = $imageupload->errString;
			else {
				$url = $imageupload->upload('storage/data');
				if($imageupload->width > 500 || $imageupload->height > 500);
				if(in_array(spost('type'),array('logo')))
					$imageupload->resize($url,200,200);
				if(sget('imgkeysed') == 'icons') {
					if($imageupload->width > 30)
						$imageupload->resize($url,24,24);
				}
				 
				$dburl = str_replace('../','',$url);
			}
			$str = "{ error: '$error', dburl: '$dburl' , vurl : '$url' }";
			echo $str ;
			exit();
		}
	}
	
	if ($_GET['ajax']=='cutimage') {
		$targ_w = $targ_h = 150;
		$jpeg_quality = 90;
	
		$src = $_POST['u'];
		$img_r = imagecreatefromjpeg($src);
		$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
		imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],	$targ_w,$targ_h,$_POST['w'],$_POST['h']);
		
		$str = "{ error: 'none'}";
 		echo $str ;
		exit();
	}

if($_GET['ajax']=="serverfile"){

	$_POST['dir'] = urldecode($_POST['dir']);
	if( file_exists($root . $_POST['dir']) ) {
		$files = scandir($root . $_POST['dir']);
		natcasesort($files);
		if( count($files) > 2 ) { /* The 2 accounts for . and .. */
			echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
			// All dirs
			foreach( $files as $file ) {
				if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && is_dir($root . $_POST['dir'] . $file) ) {
					echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "/\">" . htmlentities($file) . "</a></li>";
				}
			}
			// All files
			foreach( $files as $file ) {
				if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && !is_dir($root . $_POST['dir'] . $file) ) {
					$ext = preg_replace('/^.*\./', '', $file);
					echo "<li class=\"file ext_$ext\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "\">" . htmlentities($file) . "</a></li>";
				}
			}
			echo "</ul>";	
		}
	}
}
if($_GET['ajax']=="sortbss"){
		$data = spost('data');
		preg_match_all("/([0-9]*?)\,/",$data,$arr);
		require_once('../includes/business.ctefx.php');
		ce_business::sortList($arr[1]);
		
		
		
}

if($_GET['ajax']=="sortspo"){
		$data = spost('data');
		preg_match_all("/([0-9]*?)\,/",$data,$arr);
		require_once('../includes/sponsor.ctefx.php');
		ce_sponsor::sortspo($arr[1]);
		
		
		
}
?>